package edu.gatech.aristotle.random.experiment;

import java.io.IOException;
import java.util.ArrayList;

import net.util.Debug;

import edu.gatech.aristotle.random.ineqalities.ChernoffBound;
import edu.gatech.aristotle.random.util.GCC_RandomTestCaseConverter;
import edu.gatech.aristotle.random.util.RandomnessSelector;
import edu.gatech.aristotle.random.util.Util_Math;

public class GCCRandomness {
	
	public static void main(String args[]) throws IOException{
		String testOutputDir	= "gcc_testing_result";
		String outputFile		= 	//"salo_gcc.txt";
									//"salo_g++.txt";									
									//"salo_gfortran.txt";
									//"test_output.salo.insert_bug_3language.only.txt";
									
									"salo_gcc_1bug.txt";
									//"salo_g++_1bug.txt";									
									//"salo_gfortran_1bug.txt";
									//"salo_1bug.txt";
		String testOutputFile	= testOutputDir + "\\" + outputFile;
		
		ChernoffBound	chernoffBound	= new GCCRandomness().computeChernoffBound(testOutputFile);
		
		System.out.println( chernoffBound.makeReport() );
	}
	
	public ChernoffBound computeChernoffBound(String testOutputFile) throws IOException{
		GCC_RandomTestCaseConverter gc		= new GCC_RandomTestCaseConverter();
		ArrayList<Integer> testResultArray	= gc.buildResultArray(testOutputFile);
		
		int universe	= testResultArray.size();
		int actualPassed= 0;		
		for (Integer testResult : testResultArray){
			if (testResult == 0) actualPassed++;				
		}
		Debug.println( testOutputFile + "\nuniverse, actualPassed, actualFailed pass rate" + 
					"\n[" + universe + "," 
					+ actualPassed + "," + (universe - actualPassed) + "," + Util_Math.rate(actualPassed, universe) + "]");
		
		ArrayList<Integer> randomSubset		= RandomnessSelector.selectRandomSubset( testResultArray, 1000 );
		
		int 	sample		= randomSubset.size();
		int 	passed		= 0;
		
		for (Integer testResult : randomSubset){
			if (testResult == 0) passed++;			
		}
		
		double	deviation	= 0.1;
		
		ChernoffBound	chernoffBound	= new ChernoffBound( deviation, passed, sample );
		
		return chernoffBound;
	}
}
